package com.ruoyi.exam.controller;

import java.util.List;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.exam.domain.ExamArea;
import com.ruoyi.exam.service.IExamAreaService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;

/**
 * 地区管理Controller
 * 
 * @author wky
 * @date 2024-09-19
 */
@RestController
@RequestMapping("/exam/area")
@Tag(name = "【地区管理】管理")
public class ExamAreaController extends BaseController
{
    @Autowired
    private IExamAreaService examAreaService;

    /**
     * 查询地区管理列表
     */
    @Operation(summary = "查询地区管理列表")
    @PreAuthorize("@ss.hasPermi('exam:area:list')")
    @GetMapping("/list")
    public AjaxResult list(ExamArea examArea)
    {
        List<ExamArea> list = examAreaService.selectExamAreaList(examArea);
        return success(list);
    }

    /**
     * 导出地区管理列表
     */
    @Operation(summary = "导出地区管理列表")
    @PreAuthorize("@ss.hasPermi('exam:area:export')")
    @Log(title = "地区管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ExamArea examArea)
    {
        List<ExamArea> list = examAreaService.selectExamAreaList(examArea);
        ExcelUtil<ExamArea> util = new ExcelUtil<ExamArea>(ExamArea.class);
        util.exportExcel(response, list, "地区管理数据");
    }

    /**
     * 获取地区管理详细信息
     */
    @Operation(summary = "获取地区管理详细信息")
    @PreAuthorize("@ss.hasPermi('exam:area:query')")
    @GetMapping(value = "/{areaId}")
    public AjaxResult getInfo(@PathVariable("areaId") Long areaId)
    {
        return success(examAreaService.selectExamAreaByAreaId(areaId));
    }

    /**
     * 新增地区管理
     */
    @Operation(summary = "新增地区管理")
    @PreAuthorize("@ss.hasPermi('exam:area:add')")
    @Log(title = "地区管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ExamArea examArea)
    {
        return toAjax(examAreaService.insertExamArea(examArea));
    }

    /**
     * 修改地区管理
     */
    @Operation(summary = "修改地区管理")
    @PreAuthorize("@ss.hasPermi('exam:area:edit')")
    @Log(title = "地区管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ExamArea examArea)
    {
        return toAjax(examAreaService.updateExamArea(examArea));
    }

    /**
     * 删除地区管理
     */
    @Operation(summary = "删除地区管理")
    @PreAuthorize("@ss.hasPermi('exam:area:remove')")
    @Log(title = "地区管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{areaIds}")
    public AjaxResult remove(@PathVariable( name = "areaIds" ) Long[] areaIds) 
    {
        return toAjax(examAreaService.deleteExamAreaByAreaIds(areaIds));
    }
}
